clear all
set more off
cap log close
********************************************************************************
***** Project: The Short and Long Term Effects of In-Person Performance Feedback
********************************************************************************
***** A. R. Soetevent & G. J. Romensen
********************************************************************************
***** Basic pictures 
********************************************************************************
*global filepath "C:\JPEMicReplication"
*global paperpath "$filepath\TablesGraphs"
local abcd "acceleratie rem bochten fueleconomyLpKM"
log using "$filepath/Logs/X02BasicPictures.log", replace

/*** Notes ***/
* No fuel economy observations postfeedback in urban area.

use "$filepath\DEPO\DataMainAnalysisDEPO.dta"

* Drop eco-coaches [chauf_nr_rug: randomly generated depository numbers!]
local eco_nr "939 1404 519 1286 1610 531 936 594 808 1297 1618 731 1402"
* Drop ZH data
drop if regio == "ZH"

* Which bus type used where? 
tab voertuig_omschrijving traject

*********************************************
*** Basic Pictures Trends in ABC&F dimensions
*********************************************
replace bustype=1 if strpos(voertuig_omschrijving, "VDL")
replace bustype=2 if strpos(voertuig_omschrijving, "INTOURO")
replace bustype=3 if strpos(voertuig_omschrijving, "IRISBUS")

**********************************************************************************************************************************************
***  [Figure I.6: Development Over Time in ABC Dimensions (No. Events) and Fuel Economy (liters/100km) – Weekly Averages by Bus Type]
**********************************************************************************************************************************************

local abcd "acceleratie rem bochten fueleconomyLpKM"
local teller=0
foreach var of local abcd {
	local teller=`teller' + 1
	forv k = 1/3 {
		if `teller'<4 {
		local tekst=`"xline(6.5, lp(".") lc(gs3))  xline(10.5, lc(red) lp(shortdash))  xline(15.5, lc(green) lp(shortdash)) xline(63.5, lc(blue) lp(shortdash)) omitted xline(20.5 24.5 28.5 33.5 37.5 42.5 46.5 51.5 55.5 59.5, lp(dot) lc(gs3))  xlabel(1 "01/09/15" 27 "01/03/16" 53 "01/09/16" 72 "01/01/17")"'
		local ynaam  "Events per 10km [VDL, INTOURO]" 
		local ynaam2  "Events per 10km [IRIS]" 
		}
		if `teller'==4 {
		local tekst=`"xline(40.5, lp(".") lc(gs3))   xline(44.5, lc(red) lp(shortdash))  xline(49.5, lc(green) lp(shortdash)) xline(97.5, lc(blue) lp(shortdash)) omitted  xline(54.5 58.5 62.5 67.5 71.5 76.5 80.5 85.5 89.5 93.5, lp(dot) lc(gs3))  xlabel(1 "01/01/15" 27 "01/07/15" 53 "01/01/16" 79 "01/07/16" 104 "01/01/17")"'
		local ynaam  "Fuel economy (liters/100km)" 
		local ynaam2  "" 
		}

		if (`teller'<4 | `k'<3) {
		reg dep_`var' i.weekindex if bustype==`k', noconstant vce(cl chauf_nr_rug)
		estimates store m`var'BT`k'
		}
	}
	if `teller'<4 {
	coefplot (m`var'BT1, yaxis(1)) (m`var'BT2, yaxis(1)) (m`var'BT3, yaxis(2)), keep(*weekindex*) noci recast(line) msize(small)  vertical lcolor(%70)  lwidth(medium)  ///
			`tekst' xtitle("Date") ytitle("`ynaam'", axis(1)) ytitle("`ynaam2'", axis(2)) legend(order(1 "VDL" 2 "INTOURO" 3 "IRIS") pos(6) rows(1)) ///
			graphregion(fcolor(white) lcolor(white)) bgcolor(white) name(Wk`var'ALLbyBT, replace)
			graph export "$paperpath/Wk`var'ALLbyBT.png", replace name(Wk`var'ALLbyBT) 
	}
	if `teller'==4 {
	
	coefplot (m`var'BT1) (m`var'BT2), keep(*weekindex*) noci recast(line) msize(small)  vertical lcolor(%70)  lwidth(medium)  ///
			`tekst' xtitle("Date") ytitle("`ynaam'", axis(1)) legend(order(1 "VDL" 2 "INTOURO") pos(6) rows(1)) ///
			graphregion(fcolor(white) lcolor(white)) bgcolor(white) name(Wk`var'ALLbyBT, replace)
			graph export "$paperpath/Wk`var'ALLbyBT.png", replace name(Wk`var'ALLbyBT) 
	}
}


graph close
log close
